package com.cg.service;

import com.cg.mapper.OrderPublicMapper;
import com.cg.po.OrderPO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;

@Service
@RequiredArgsConstructor
public class OrderService {

    private final OrderPublicMapper orderPublicMapper;

    @Transactional
    public Boolean generateOrder(Integer userId,Integer orderNum){
        OrderPO build = OrderPO.builder()
                .userId(userId)
                .orderNum(orderNum)
                .orderCode(UUID.randomUUID().toString().replace("-","").substring(0,8))
                .build();
        return orderPublicMapper.insert(build) > 0;
    }

}
